home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / cxref_1_4a.lha / warn-raw.c < prev    next >
C/C++ Source or Header  |  1997-12-07  |  18KB  |  628 lines

  1. /***************************************
  2.   $Header: /home/amb/cxref/RCS/warn-raw.c 1.23 1997/11/20 19:19:07 amb Exp $
  3.  
  4.   C Cross Referencing & Documentation tool. Version 1.4a.
  5.  
  6.   Writes the raw information and / or warnings out.
  7.   ******************/ /******************
  8.   Written by Andrew M. Bishop
  9.  
  10.   This file Copyright 1995,96,97 Andrew M. Bishop
  11.   It may be distributed under the GNU Public License, version 2, or
  12.   any higher version.  See section COPYING of the GNU Public license
  13.   for conditions under which this file may be redistributed.
  14.   ***************************************/
  15.  
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19.  
  20. #ifdef AMIGA /* olsen */
  21. #include "amiga.h"
  22. #endif /* AMIGA */
  23.  
  24. #include "datatype.h"
  25. #include "cxref.h"
  26. #include "memory.h"
  27.  
  28. static void WriteWarnRawFilePart(File file);
  29. static void WriteWarnRawInclude(Include inc);
  30. static void WriteWarnRawSubInclude(Include inc,int depth);
  31. static void WriteWarnRawDefine(Define def);
  32. static void WriteWarnRawTypedef(Typedef type);
  33. static void WriteWarnRawStructUnion(StructUnion su, int depth,StructUnion base);
  34. static void WriteWarnRawVariable(Variable var);
  35. static void WriteWarnRawFunction(Function func);
  36.  
  37. /*+ Output option. +*/
  38. extern int option_warn,option_raw,option_xref,option_index;
  39.  
  40. /*+ The name of the current file. +*/
  41. static char* filename=NULL;
  42.  
  43. /*++++++++++++++++++++++++++++++++++++++
  44.   Write the raw / warning output for a complete File structure and all components.
  45.  
  46.   File file The File structure to output.
  47.   ++++++++++++++++++++++++++++++++++++++*/
  48.  
  49. void WriteWarnRawFile(File file)
  50. {
  51.  Include   inc =file->includes;
  52.  Define    def =file->defines;
  53.  Typedef   type=file->typedefs;
  54.  Variable  var=file->variables;
  55.  Function  func=file->functions;
  56.  
  57.  filename=file->name;
  58.  
  59.  /*+ The file structure is broken into its components and they are each written out. +*/
  60.  
  61.  if(option_raw)
  62.     printf("----------------------------------------\n");
  63.  
  64.  WriteWarnRawFilePart(file);
  65.  
  66.  while(inc)
  67.    {
  68.     WriteWarnRawInclude(inc);
  69.     inc=inc->next;
  70.    }
  71.  
  72.  while(def)
  73.    {
  74.     WriteWarnRawDefine(def);
  75.     def=def->next;
  76.    }
  77.  
  78.  while(type)
  79.    {
  80.     WriteWarnRawTypedef(type);
  81.     type=type->next;
  82.    }
  83.  
  84.  while(var)
  85.    {
  86.     WriteWarnRawVariable(var);
  87.     var=var->next;
  88.    }
  89.  
  90.  while(func)
  91.    {
  92.     WriteWarnRawFunction(func);
  93.     func=func->next;
  94.    }
  95.  
  96.  if(option_raw)
  97.     printf("----------------------------------------\n\n");
  98. }
  99.  
  100.  
  101. /*++++++++++++++++++++++++++++++++++++++
  102.   Write a File structure out.
  103.  
  104.   File file The File structure to output.
  105.   ++++++++++++++++++++++++++++++++++++++*/
  106.  
  107. static void WriteWarnRawFilePart(File file)
  108. {
  109.  int i;
  110.  
  111.  if(option_raw)
  112.     printf("FILE : '%s'\n",file->name);
  113.  
  114.  if(file->comment && option_raw)
  115.     printf("<<<\n%s\n>>>\n",file->comment);
  116.  
  117.  if(option_warn&WARN_COMMENT && !file->comment)
  118.     printf("Warning %16s : File does not have a comment.\n",filename);
  119.  
  120.  if(option_xref&XREF_FILE)
  121.    {
  122.     if(option_raw)
  123.        for(i=0;i<file->inc_in->n;i++)
  124.           printf("Included in %s\n",file->inc_in->s[i]);
  125.  
  126.     if(option_warn&WARN_XREF)
  127.       {
  128.        int len=strlen(file->name)-2;
  129.        if(!file->inc_in->n && !strcmp(&file->name[len],".h"))
  130.           printf("Warning %16s : Header file %s is not included in any files.\n",filename,file->name);
  131.        if( file->inc_in->n && !strcmp(&file->name[len],".c"))
  132.           printf("Warning %16s : Source file %s is included in another file.\n",filename,file->name);
  133.       }
  134.    }
  135.  
  136.  if(option_xref&XREF_FUNC)
  137.     for(i=0;i<file->f_refs->n;i++)
  138.       {
  139.        if(option_raw)
  140.           if(file->f_refs->s2[i])
  141.              printf("References Function %s : %s\n",file->f_refs->s1[i],file->f_refs->s2[i]);
  142.           else
  143.              printf("References Function %s\n",file->f_refs->s1[i]);
  144.        if(option_warn&WARN_XREF && !file->f_refs->s2[i])
  145.           printf("Warning %16s : File references function %s() whose definition is unknown.\n",filename,file->f_refs->s1[i]);
  146.       }
  147.  
  148.  if(option_xref&XREF_VAR)
  149.     for(i=0;i<file->v_refs->n;i++)
  150.       {
  151.        if(option_raw)
  152.           if(file->v_refs->s2[i])
  153.              printf("References Variable %s : %s\n",file->v_refs->s1[i],file->v_refs->s2[i]);
  154.           else
  155.              printf("References Variable %s\n",file->v_refs->s1[i]);
  156.        if(option_warn&WARN_XREF && !file->v_refs->s2[i])
  157.           printf("Warning %16s : File references variable %s whose definition is unknown.\n",filename,file->v_refs->s1[i]);
  158.       }
  159. }
  160.  
  161.  
  162. /*++++++++++++++++++++++++++++++++++++++
  163.   Write an Include structure out.
  164.  
  165.   Include inc The Include structure to output.
  166.   ++++++++++++++++++++++++++++++++++++++*/
  167.  
  168. static void WriteWarnRawInclude(Include inc)
  169. {
  170.  if(option_raw)
  171.     printf("\nINCLUDES : '%s' [%s file]\n",inc->name,(inc->scope==GLOBAL?"System":"Local"));
  172.  
  173.  if(inc->comment && option_raw)
  174.     printf("<<<\n%s\n>>>\n",inc->comment);
  175.  if(option_warn&WARN_COMMENT && !inc->comment)
  176.     printf("Warning %16s : #Include %s does not have a comment.\n",filename,inc->name);
  177.  
  178.  if(option_raw && inc->includes)
  179.     WriteWarnRawSubInclude(inc->includes,1);
  180. }
  181.  
  182.  
  183. /*++++++++++++++++++++++++++++++++++++++
  184.   Write an Sub-Include structure out.
  185.  
  186.   Include inc The Include structure to output.
  187.  
  188.   int depth The depth of the include hierarchy.
  189.   ++++++++++++++++++++++++++++++++++++++*/
  190.  
  191. static void WriteWarnRawSubInclude(Include inc,int depth)
  192. {
  193.  int i;
  194.  
  195.  while(inc)
  196.    {
  197.     for(i=0;i<depth;i++) printf("   ");
  198.     printf("INCLUDES : '%s' [%s file]\n",inc->name,(inc->scope==GLOBAL?"System":"Local"));
  199.  
  200.     if(inc->includes)
  201.        WriteWarnRawSubInclude(inc->includes,depth+1);
  202.  
  203.     inc=inc->next;
  204.    }
  205. }
  206.  
  207.  
  208. /*++++++++++++++++++++++++++++++++++++++
  209.   Write a Define structure out.
  210.  
  211.   Define def The Define structure to output.
  212.   ++++++++++++++++++++++++++++++++++++++*/
  213.  
  214. static void WriteWarnRawDefine(Define def)
  215. {
  216.  int i;
  217.  
  218.  if(option_raw)
  219.    {
  220.     printf("\nDEFINES : '%s' ",def->name);
  221.  
  222.     if(def->value)
  223.        printf("= %s",def->value);
  224.  
  225.     if(def->args->n)
  226.       {
  227.        printf("(");
  228.        for(i=0;i<def->args->n;i++)
  229.           printf(i?",%s":"%s",def->args->s1[i]);
  230.        printf(")");
  231.       }
  232.  
  233.     printf("\n");
  234.    }
  235.  
  236.  if(def->comment && option_raw)
  237.     printf("<<<\n%s\n>>>\n",def->comment);
  238.  if(option_warn&WARN_COMMENT && !def->comment)
  239.     printf("Warning %16s : #Define %s does not have a comment.\n",filename,def->name);
  240.  
  241.  for(i=0;i<def->args->n;i++)
  242.    {
  243.     if(option_raw)
  244.        if(def->args->s2[i])
  245.           printf("Arguments: %s <<<%s>>>\n",def->args->s1[i],def->args->s2[i]);
  246.        else
  247.           printf("Arguments: %s\n",def->args->s1[i]);
  248.     if(option_warn&WARN_COMMENT && !def->args->s2[i])
  249.        printf("Warning %16s : #Define %s has an argument %s with no comment.\n",filename,def->name,def->args->s1[i]);
  250.    }
  251. }
  252.  
  253.  
  254. /*++++++++++++++++++++++++++++++++++++++
  255.   Write a Typedef structure out.
  256.  
  257.   Typedef type The Typedef structure to output.
  258.   ++++++++++++++++++++++++++++++++++++++*/
  259.  
  260. static void WriteWarnRawTypedef(Typedef type)
  261. {
  262.  if(option_raw)
  263.     if(type->type)
  264.        printf("\nTYPEDEF : '%s'\n",type->name);
  265.     else
  266.        printf("\nTYPE : '%s'\n",type->name);
  267.  
  268.  if(type->comment && option_raw)
  269.     printf("<<<\n%s\n>>>\n",type->comment);
  270.  if(option_warn&WARN_COMMENT && !type->comment)
  271.     printf("Warning %16s : Type %s does not have a comment.\n",filename,type->name);
  272.  
  273.  if(option_raw)
  274.     if(type->type)
  275.        printf("Type: %s\n",type->type);
  276.  
  277.  if(option_raw)
  278.     if(type->typexref)
  279.        printf("See: %s %s\n",type->typexref->type?"Typedef":"Type",type->typexref->name);
  280.  
  281.  if(type->sutype)
  282.     WriteWarnRawStructUnion(type->sutype,0,type->sutype);
  283. }
  284.  
  285.  
  286. /*++++++++++++++++++++++++++++++++++++++
  287.   Write a structure / union / enum out.
  288.  
  289.   StructUnion su The structure / union / enum to write.
  290.  
  291.   int depth The depth within the structure.
  292.  
  293.   StructUnion base The base struct union that this one is part of.
  294.   ++++++++++++++++++++++++++++++++++++++*/
  295.  
  296. static void WriteWarnRawStructUnion(StructUnion su, int depth,StructUnion base)
  297. {
  298.  int i;
  299.  char* splitsu=NULL;
  300.  
  301.  if(option_warn&WARN_COMMENT && depth && !su->comment)
  302.     printf("Struct/Union component %s in %s does not have a comment.\n",su->name,base->name);
  303.  
  304.  splitsu=strstr(su->name,"{...}");